package com.study.lu;

public class Demo1 {
    public static void main(String[] args) {
        String compare = "abc";
        String tagretStr = "aaaabcccccdddd";

        System.out.println(getIndexOf(compare,tagretStr));
    }

    private static Long getIndexOf(String compare, String tagretStr) {
        int compareHashCode = compare.hashCode();

        int compareSize = compare.length();
        String[] split = compare.split("");
        int index =0;
        while (index<tagretStr.length()){
            String substring = tagretStr.substring(index, index+compareSize);
            if(substring.hashCode()==compareHashCode){
                String[] split1 = substring.split("");
                boolean issame = true;
                for (int i = 0; i < split.length; i++) {
                    if(!split[i].equals(split1[i])){
                        issame = false;
                        break;
                    }
                }
                if(issame){
                    return Long.valueOf(index) ;
                }
            }
            index++;
        }

        return -1L;
    }
}
